package com.financing.platform.dao.impl;

import java.sql.SQLException;
import java.util.Collections;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.financing.platform.dao.ICompanyDao;
import com.financing.platform.dto.CompanyDTO;
import com.financing.platform.dto.CompanyInvitationCodeDTO;
import com.financing.platform.util.SqlName;


@Repository("companyDaoImpl")
public class CompanyDaoImpl extends BaseDaoImpl implements ICompanyDao {

	public int addComany(CompanyDTO companyDTO) throws SQLException {
		return (Integer) this.sqlMapClient.insert(SqlName.addCompany, companyDTO);
	}

	@SuppressWarnings("unchecked")
	public List<CompanyDTO> queryComanyList(CompanyDTO companyDTO) {
		try {
			return this.sqlMapClient.queryForList(SqlName.queryCompany, companyDTO);
		} catch (SQLException e) {
			log.error("Query Comany List error !",e);
			return Collections.emptyList();
		}
	}

	public int updateComany(CompanyDTO companyDTO) throws SQLException {
		return this.sqlMapClient.update(SqlName.updateCompany,companyDTO);
	}
	
	public int makeComanyUser(CompanyInvitationCodeDTO cic) throws SQLException{
		return this.sqlMapClient.update(SqlName.makeCompanyUser, cic);
	}

	@Override
	public int addCompanyInvitationCode(CompanyInvitationCodeDTO cic)
			throws SQLException {
		return (Integer) this.sqlMapClient.insert(SqlName.addCompanyInvitationCode,cic);
	}
	
}
